﻿using BrnMall.Manager.Domain.Product;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Manager.Manager.Product
{
    public class ProductExtendManager
    {
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(ProductExtend model)
        {
            object obj = null;
            using (var db = new QDMallDatabase())
            {
                obj = db.Insert(model);
            }
            if (obj != null)
                return true;
            return false;
        }

        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Update(ProductExtend model)
        {
            int count = 0;
            using (var db = new QDMallDatabase())
            {
                count = db.Execute("update bma_ProductExtend set StoreId=@0,AppCode=@1 where pid=@2", model.StoreId, model.AppCode, model.Pid);
            }
            return count > 0;
        }

        /// <summary>
        /// 获取单条记录
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public static ProductExtend Get(int pid)
        {
            if (pid < 1) return null;
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<ProductExtend>("select top 1 * from bma_ProductExtend where pid=@0", pid);
            }
        }
    }
}